home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / mail-tools / thor / thor_2.22 / thor.lha / rexx / GetHTTP.thor < prev    next >
Text File  |  1995-12-18  |  5KB  |  216 lines

  1. /*
  2.  $VER: GetHTTP.Thor 2.0b2 by Remco van Hooff
  3. */
  4.  
  5. hotlist_amosaic = 'envarc:mosaic/.mosaic-hotlist-default'
  6. amosaic = 1
  7. hotlist_ibrowse = 'IBrowse:prefs/hotlist'
  8. ibrowse = 1
  9. hotlist_html    = 'path_to_hotlist:hotlist.html'
  10. html    = 0
  11.  
  12. /* don't edit these */
  13. cr = '0d'x
  14. lf = '0a'x
  15.  
  16. /* filter chars, expand if you want */
  17. filter.1 = cr
  18. filter.2 = lf
  19. filter.3 = ')'
  20. filter.4 = ','
  21. filter.5 = "'"
  22. filter.6 = '"'
  23. filter.7 = ']'
  24. filter.8 = '>'
  25. filter.9 = '}'
  26. filter.count = 9     /* number of chars */
  27.  
  28. /* --- no need to edit anything below this line --- */
  29. tempfile  = 't:http.tmp'
  30. space   = '                    '
  31. drop name.
  32.  
  33. options failat 31
  34. p = address() || ' ' || show('P',,)
  35. thorport = pos('THOR.',p)
  36. if thorport > 0 then thorport = word(substr(p,thorport),1)
  37. else do
  38.   say 'THOR port not found!'
  39.   exit 10
  40. end
  41.  
  42. if ~show('p', 'BBSREAD') then do
  43.   address command
  44.     "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  45.     "WaitForPort BBSREAD"
  46. end
  47.  
  48. address(thorport)
  49. options results
  50.  
  51. CURRENTMSG stem MSG
  52. if(rc ~= 0) then do
  53.   REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  54.   exit
  55. end
  56. msgnum = MSG.MSGNR
  57. bbs    = MSG.BBSNAME
  58. conf   = MSG.CONFNAME
  59.  
  60. address bbsread READBRMESSAGE BBSNAME '"'bbs'"' CONFNAME '"'conf'"' MSGNR msgnum HEADSTEM headtags
  61. if(rc ~= 0) then do
  62.   REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  63.   exit
  64. end
  65. subj = HEADTAGS.SUBJECT
  66. if pos('RE:',UPPER(subj)) ~=0 then subj = substr(subj,5)
  67.  
  68. SAVEMESSAGE CURRENT FILENAME tempfile NOHEADER NOANSI OVERWRITE
  69. if(rc ~= 0) then do
  70.   REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  71.   exit
  72. end
  73.  
  74. else do
  75.   call open(tmp, tempfile, 'r')
  76.     num = 0
  77.     do while ~eof(tmp)
  78.       msg = readln(tmp)
  79.       msg = translate(msg, 'hpt', 'HPT')
  80.       parse var msg . 'ttp://' httpadres .
  81.       if httpadres ~= '' then do
  82.         num = num + 1
  83.         lengte = length(httpadres)   
  84.         call filter(httpadres, lengte)
  85.         found.num = httpadres
  86.         found.count = num
  87.       end
  88.     end
  89.   call close(tmp)
  90.   address command 'delete >nil: 'tempfile
  91.   if found.0 = 0 then 'requestnotify text "No URL found." bt "_OK"'
  92. end
  93.  
  94. call listfound
  95.  
  96. if ok = 1 then do
  97.   listsave:
  98.       do i = 1 to save.count
  99.         if name.i = 'NAME.'i then name.i = space
  100.         show.i = name.i' - 'save.i
  101.       end
  102.       sep = save.count +1
  103.       but = save.count +2
  104.       show.sep = ''
  105.       show.but = 'SAVE'
  106.       show.count = save.count+2
  107.     REQUESTLIST INSTEM show TITLE '"Select to enter a name"' SIZEGADGET
  108.     if (rc = 30) then do
  109.       REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  110.       exit
  111.     end
  112.     if rc ~= 5 then do
  113.       selected = result
  114.       do n = 1 to save.count
  115.         if selected = show.n then do
  116.           if name.n = space then name.n = ''
  117.           REQUESTSTRING title '"Enter a name"' BT '"_OK"' BODY '"'save.n'"' MAXCHARS 20 INITIALSTRING '"'name.n'"'
  118.           name.n = LEFT(result,20,' ')
  119.         end
  120.         if selected = 'SAVE' then signal savehotlist
  121.       end
  122.     signal listsave
  123.     end
  124. end
  125. EXIT
  126.  
  127. filter:
  128.   adres = arg(1)
  129.   lngth = arg(2)
  130.   do i = 1 to filter.count
  131.     check = pos(filter.i, adres)
  132.     if check ~=0 then do
  133.       adres = delstr(adres, check)
  134.     end
  135.   end
  136.   punt = lastpos('.', adres)
  137.   if punt ~=0 then lngth = length(adres)
  138.   if (punt = lngth) then do
  139.     adres = delstr(adres, punt)
  140.   end
  141.   httpadres = 'http://'||adres
  142. return
  143.  
  144. listfound:
  145.   if found.COUNT > 0 then do
  146.     REQUESTLIST instem found outstem save title '"Select URL(s) to save"' MULTISELECT SIZEGADGET
  147.     if (rc = 30) then do
  148.       REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  149.       exit
  150.     end
  151.   end
  152.   if rc ~= 5 then ok = 1
  153.   if found.COUNT = 0 then do
  154.     REQUESTNOTIFY '"No URLs found in this message"' '"_Ok"'
  155.     exit
  156.   end
  157. return
  158.  
  159. savehotlist:
  160.   DO i = 1 TO save.count
  161.     IF name.i = '' THEN name.i = 'GetHTTP -' subj '('i')'
  162.   END
  163.   IF amosaic = 1 then call save_amosaic
  164.   IF ibrowse = 1 then call save_ibrowse
  165.   IF html    = 1 then call save_html
  166. exit
  167.  
  168. save_amosaic:
  169.   IF ~EXISTS(hotlist_amosaic) THEN DO
  170.     Requestnotify '"Amosaic hotlist not found!"' '"_OK"'
  171.     RETURN
  172.   END
  173.   ELSE DO
  174.     dat = date()
  175.     parse var dat dagnr maand jaar
  176.     dag = left(date('W', date(S), 'S'), 3)
  177.     datum = dag maand dagnr time()jaar
  178.     CALL OPEN(htlst,hotlist_amosaic,'a')
  179.     DO i = 1 TO save.count
  180.       CALL WRITELN(htlst,save.i||' '||datum)
  181.       CALL WRITELN(htlst,STRIP(name.i))
  182.     end
  183.     CALL CLOSE(htlst)
  184.   END
  185.   ADDRESS COMMAND 'copy' hotlist_amosaic 'env:mosaic/'
  186. RETURN
  187.  
  188. save_ibrowse:
  189.   IF ~EXISTS(hotlist_ibrowse) THEN DO
  190.     Requestnotify '"IBrowse hotlist not found!"' '"_OK"'
  191.     RETURN
  192.   END
  193.   ELSE DO
  194.     CALL OPEN(htlst,hotlist_ibrowse,'a')
  195.     DO i = 1 TO save.count
  196.       CALL WRITELN(htlst,save.i)
  197.       CALL WRITELN(htlst,STRIP(name.i))
  198.     end
  199.     CALL CLOSE(htlst)
  200.   END
  201. RETURN
  202.  
  203. save_html:
  204.   IF ~EXISTS(hotlist_html) THEN DO
  205.     Requestnotify '"HTML hotlist not found!"' '"_OK"'
  206.     RETURN
  207.   END
  208.   ELSE DO
  209.     CALL OPEN(htlst,hotlist_html,'a')
  210.     DO i = 1 TO save.count
  211.       CALL WRITELN(htlst,'<LI><A HREF="'save.i'">'STRIP(name.i)'</A><br>')
  212.     end
  213.     CALL CLOSE(htlst)
  214.   END
  215. RETRUN
  216.